const ejs = require('ejs');
const fs = require('fs');
const app = {
    //login
    login:function(req, res){
        console.log('login');
        ejs.renderFile('views/form.ejs', {}, function(err, data){
            res.end(data);
        })
    },
    doLogin:function(req, res){
        let postStr = '';
        req.on('data', function(chunk){
            postStr += chunk;
        });
        req.on('end', function(err, chunk){
            console.log(postStr);
            fs.appendFile('login.txt', postStr + '\n', function(err){
                if(err){
                    console.log(err);
                    return;
                }
                console.log('写入数据成功');
            });
            res.end("<script>alert('登录成功');history.back();</script>");
        })
    },
    register:function(req, res){
        console.log('register');
        res.end('register');
    },
    home:function(req, res){
        console.log('home');
        res.end('home');
    }
}

module.exports = app;